package socketmina.server;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @ClassName TcpServerHandler
 * @Description TODO
 * @Author yuanweimin
 * @Date 2018/8/23 19:54
 * @Version 1.0
 **/
public class TcpServerHandler extends IoHandlerAdapter {

    private static  final Logger logger = LoggerFactory.getLogger(TcpServerHandler.class);
    @Override
    public void sessionCreated(IoSession session) throws Exception {
        System.out.println("session create");
        super.sessionCreated(session);

    }

    @Override
    public void sessionOpened(IoSession session) throws Exception {
        System.out.println("session open");
        super.sessionOpened(session);
    }

    @Override
    public void sessionClosed(IoSession session) throws Exception {
        System.out.println("session close");
        super.sessionClosed(session);
    }

    @Override
    public void messageReceived(IoSession session, Object message) throws Exception {
        super.messageReceived(session, message);
        String string = message.toString();
        System.out.println("收到消息：" + string);
        if (string.endsWith("quit")){
            session.close(true);
            return;
        }
    }

    @Override
    public void messageSent(IoSession session, Object message) throws Exception {
        super.messageSent(session, message);
    }
}
